
Imports System.Data
Imports System.Data.SqlClient


Namespace general
Public Class sysdiagrams

public Function Listar(Diagram_id as integer) as Entity.general.sysdiagrams

Dim strNameProcedure as string = "up_general_sysdiagrams_obtener"
Dim sqlReader As SqlDataReader = Nothing
Dim sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
dim objEnt as   entity.general.sysdiagrams
Try
            sqlCon.Open()
Dim sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
.CommandType = CommandType.StoredProcedure
                .Parameters.Add(New SqlParameter("@Diagram_id", SqlDbType.Int)).Value =Diagram_id
            End With
            sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlReader.HasRows Then
While sqlReader.Read
 objEnt= new    entity.general.sysdiagrams
With objEnt
		.Name = sqlReader("Name").ToString
		.Principal_id = sqlReader("Principal_id").ToString
		.Diagram_id = sqlReader("Diagram_id").ToString
		.Version = sqlReader("Version").ToString
		.Definition = sqlReader("Definition").ToString
End With
  End While
  End IF
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 sqlReader.Dispose()
  sqlReader.Close()
  sqlReader = Nothing
  sqlCon.Dispose()
 sqlCon.Close()
 sqlCon = Nothing
 End Try
return objEnt

End Function


'***************************



public Function Listar(Opcion as string , _
		Name as String, _
		Principal_id as Integer, _
		Diagram_id as Integer, _
		Version as Integer, _
		Definition as String) _
as  Entity.general.sysdiagramsCol

Dim strNameProcedure as string = "up_general_sysdiagrams_listar"
dim objCol as   entity.general.sysdiagramsCol
Try
Using conn As New SqlConnection(Configuracion.Connexion.Cnn)
Dim cmd As New SqlCommand(strNameProcedure, conn)
cmd.CommandType = CommandType.StoredProcedure
  cmd.Parameters.Add(New SqlParameter("@opcion", SqlDbType.varchar,50)).Value =Opcion
 cmd.Parameters.Add(New SqlParameter("@Name",SqlDbType.NVARCHAR,256)).Value =Name
 cmd.Parameters.Add(New SqlParameter("@Principal_id",SqlDbType.INT)).Value =Principal_id
 cmd.Parameters.Add(New SqlParameter("@Diagram_id",SqlDbType.INT)).Value =Diagram_id
 cmd.Parameters.Add(New SqlParameter("@Version",SqlDbType.INT)).Value =Version
 cmd.Parameters.Add(New SqlParameter("@Definition",SqlDbType.VARBINARY)).Value =Definition
conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader()
		dim iName as integer = dr.GetOrdinal("Name")
		dim iPrincipal_id as integer = dr.GetOrdinal("Principal_id")
		dim iDiagram_id as integer = dr.GetOrdinal("Diagram_id")
		dim iVersion as integer = dr.GetOrdinal("Version")
		dim iDefinition as integer = dr.GetOrdinal("Definition")

 Dim colCount As Integer = dr.FieldCount
 Dim values As Object() = New Object(colCount - 1) {}

 objCol =  New entity.general.sysdiagramsCol
  If dr.HasRows Then
While dr.Read()
dim objEnt =  new entity.general.sysdiagrams
dr.GetValues(values)

		objEnt.Name = values(iName)
		objEnt.Principal_id = values(iPrincipal_id)
		objEnt.Diagram_id = values(iDiagram_id)
		objEnt.Version = values(iVersion)
		objEnt.Definition = values(iDefinition)
 objCol.Add(objEnt)
 End While
 End if
 End Using
 End Using
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 End Try
return objCol

End Function


'***************************


Public Shared Function Insert(ByVal opcion As String, _
		Name as String, _
		Principal_id as Integer, _
		Diagram_id as Integer, _
		Version as Integer, _
		Definition as String) _
 As Integer

 dim strNameProcedure as string ="Up_Sysdiagrams_Insertar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@Name",SqlDbType.NVARCHAR,256)).Value =Name
 .Parameters.Add(New SqlParameter("@Principal_id",SqlDbType.INT)).Value =Principal_id
 .Parameters.Add(New SqlParameter("@Diagram_id",SqlDbType.INT)).Value =Diagram_id
 .Parameters.Add(New SqlParameter("@Version",SqlDbType.INT)).Value =Version
 .Parameters.Add(New SqlParameter("@Definition",SqlDbType.VARBINARY)).Value =Definition
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Update(ByVal opcion As String, _
		Name as String, _
		Principal_id as Integer, _
		Diagram_id as Integer, _
		Version as Integer, _
		Definition as String) _
 As Integer

 dim strNameProcedure as string ="Up_Sysdiagrams_Actualizar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@Name",SqlDbType.NVARCHAR,256)).Value =Name
 .Parameters.Add(New SqlParameter("@Principal_id",SqlDbType.INT)).Value =Principal_id
 .Parameters.Add(New SqlParameter("@Diagram_id",SqlDbType.INT)).Value =Diagram_id
 .Parameters.Add(New SqlParameter("@Version",SqlDbType.INT)).Value =Version
 .Parameters.Add(New SqlParameter("@Definition",SqlDbType.VARBINARY)).Value =Definition
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Eliminar(ByVal opcion As String, _
		Name as String, _
		Principal_id as Integer, _
		Diagram_id as Integer, _
		Version as Integer, _
		Definition as String) _
 As Integer

 dim strNameProcedure as string ="Up_Sysdiagrams_Eliminar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
                .Parameters.Add(New SqlParameter("@Diagram_id", SqlDbType.Int)).Value =Diagram_id
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************



End Class



end namespace

